/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.projects.tests.uml2model_test.business.dao.impl;

import java.util.List;

import com.genia.toolbox.model.exemple.AssociateOfB;
import com.genia.toolbox.model.exemple.impl.AssociateOfBImpl;
import com.genia.toolbox.persistence.criteria.Criteria;
import com.genia.toolbox.persistence.criteria.enumeration.MatchMode;
import com.genia.toolbox.persistence.dao.AbstractDAO;
import com.genia.toolbox.persistence.exception.PersistenceException;
import com.genia.toolbox.projects.tests.uml2model_test.business.dao.AssociateOfBbusinessDao;

/**
 * this class is a business dao test for <code>AssociateOfBbusinessDao</code>.
 */
public class AssociateOfBbusinessDaoImpl
    extends AbstractDAO
    implements AssociateOfBbusinessDao
{

  /**
   * delete an object <code>AssociateOfBImpl</code>.
   * 
   * @param identifier
   *          the identifier of <code>AssociateOfBImpl</code>.
   * @throws PersistenceException
   *           occurs during persistence process.
   */
  public void delete(Long identifier)
      throws PersistenceException
  {
    delete(get(AssociateOfBImpl.class, identifier));
  }



  /**
   * return an object <code>AssociateOfB</code>.
   * 
   * @param identifier
   *          the identifier associated to <code>AssociateOfB</code>.
   * @return an object <code>AssociateOfB</code>.
   */
  public AssociateOfB getAssociate(Long identifier)
  {
    return get(AssociateOfBImpl.class, identifier);
  }



  /**
   * return an object <code>AssociateOfB</code>.
   * 
   * @param name
   *          the name associate to the object.
   * @return an object <code>AssociateOfB</code>.
   * @throws PersistenceException
   *           occurs during persistence process.
   */
  public AssociateOfB getAssociate(String name)
      throws PersistenceException
  {
    Criteria<AssociateOfBImpl> criteriaAssociateOfB = getCriteria(AssociateOfBImpl.class);
    criteriaAssociateOfB.addRestriction(getRestrictionsManager().ilike(getPropertyField(AssociateOfB.NAME_NAME_OF_ASSOCIATE), getConstantField(name), MatchMode.EXACT));

    AssociateOfB resAssociateOfB = simpleFindUnique(criteriaAssociateOfB);

    return resAssociateOfB;
  }



  /**
   * return a list of all object <code>AssociateOfB</code>.
   * 
   * @return a list of <code>AssociateOfB</code>.
   * @throws PersistenceException
   *           occurs during persistence process.
   */
  public List<AssociateOfBImpl> getListAssociateOfB()
      throws PersistenceException
  {
    return getAll(AssociateOfBImpl.class);
  }



  /**
   * save an object with his parameters <code>AssociateOfB</code>.
   * 
   * @param associateOfB
   *          an object <code>AssociateOfB</code>.
   * @return the identifier after saving the object.
   * @throws PersistenceException
   *           occurs during persistence process.
   */
  public Long saveAssociateOfB(AssociateOfB associateOfB)
      throws PersistenceException
  {
    AssociateOfBImpl associate = createNewAssociateOfB();

    associate.setNameOfAssociate(associateOfB.getNameOfAssociate());
    associate.setObjB(associateOfB.getObjB());

    save(associate);

    return associate.getIdentifier();
  }



  /**
   * return a new instance of <code>AssociateOfB</code>.
   * 
   * @return a new instance of <code>AssociateOfB</code>.
   */
  public AssociateOfBImpl createNewAssociateOfB()
  {
    return new AssociateOfBImpl();
  }

}
